package com.itheima.wms.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.wms.mapper.FactoryMapper;
import com.itheima.wms.pojo.PageFactory;
import com.itheima.wms.pojo.Warehouse;
import com.itheima.wms.service.FactoryService;
import com.itheima.wms.utils.PageBean;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class FactoryServiceImpl implements FactoryService {
    private final FactoryMapper factoryMapper;

    @Override
    public void addFactory(Warehouse warehouse) {
        factoryMapper.addFactory(warehouse);
    }

    @Override
    public PageBean<Warehouse> queryFactoryAll(PageFactory queryPage) {
        PageHelper.startPage(queryPage.getCurrent(),queryPage.getSize());
        Page<Warehouse> allWarehouse = factoryMapper.findAllWarehouse(queryPage);
        return new PageBean<>(allWarehouse,allWarehouse.getTotal(),allWarehouse.getPageSize());
    }

    @Override
    public Warehouse queryFactoryById(Integer id) {
        Warehouse factory = factoryMapper.queryFactoryById(id);
        return factory;
    }

    @Override
    public void updateFactory(Warehouse warehouse) {
        factoryMapper.updateFactory(warehouse);
    }

    @Override
    public List<Warehouse> queryFactoryList(Integer status) {
        List<Warehouse> warehouses = factoryMapper.queryFactoryList(status);
        return warehouses;
    }

    @Override
    public void deleteFactoryByIds(Integer[] ids) {
        factoryMapper.deleteFactoryByIds(ids);
    }
}
